let vm = new Vue({
    el: "#dbd",
    data: {
        loading: false,
        finished: false,

        msgPopover: true,
        showMsg: false,
        list: [],

        dataObj: {
            a: "123"
        },


        message: "",
        radio: '1',


        listPopover: false,
        tableListOne: [],
        tableList: [],
    },
    mounted() {
        this.getData();
        this.getListData();

    },

    methods: {
        baseUrl() {
            return leiku.baseUrl();
        },
        getData() {
            leiku.post(this.baseUrl() + '/api/2020123003907398', { aid: leiku.GetUrlParam('aid') }, res => {
                let data = res.data;
                if (data.length) {
                    this.list = data[0];
                    console.log(this.list)
                }
            })
        },
        getListData() {
            leiku.post(this.baseUrl() + '/api/2020072490138759', { id: leiku.GetUrlParam('aid') }, res => {

                let data = res.data;
                if (data.length) {
                    let nums = 0;
                    let pricesArr = [];
                    data.forEach(v => {
                        nums += v.num;
                        pricesArr.push(v.sum)
                    })

                    this.tableListOne = data.splice(1, 1);
                    this.tableListOne[0].totalPrice = this.sum(pricesArr);
                    this.tableListOne[0].totalNum = nums;
                    this.tableListOne[0].totalPishu = data.length;
                }
            })
        },

        sum(arr) {
            return arr.reduce(function(prev, curr, idx, arr){
                var sq1, sq2, m;
                try {
                    sq1 = prev.toString().split(".")[1].length;
                }
                catch (e) {
                    sq1 = 0;
                }
                try {
                    sq2 = curr.toString().split(".")[1].length;
                }
                catch (e) {
                    sq2 = 0;
                }
                m = Math.pow(10, Math.max(sq1, sq2));
                return (prev * m + curr * m) / m;
            });
        },
        addNum(num1, num2) {
            var sq1, sq2, m;
            try {
                sq1 = num1.toString().split(".")[1].length;
            }
            catch (e) {
                sq1 = 0;
            }
            try {
                sq2 = num2.toString().split(".")[1].length;
            }
            catch (e) {
                sq2 = 0;
            }
            m = Math.pow(10, Math.max(sq1, sq2));
            return (num1 * m + num2 * m) / m;
        },

        
        msgPopoverBtn(id) {
            console.log(id);
        },
        msgClose() {
            this.radio = "1";
            this.message = "";
        },

        onLoad() {
            console.log("a")
        },

        // 审核按钮
        clickMsgBtn() {
            this.showMsg = true;
        },
        // 查看列表
        clickListPopover() {
            this.listPopover = true;
            let params = {
                id: leiku.GetUrlParam('aid')
            }
            leiku.post(this.baseUrl() + '/api/2020072490138759', params, res => {
                let data = res.data;
                if (data.length) {
                    this.tableList = data;
                    this.finished = true;
                }
                // if (!data.length) {
                //     this.finished = true;
                // }
                // this.tableList.push.apply(this.tableList, data)
                // this.loading = false;
            })
        },
        onSubmit() {
            let params = {
                rsid: this.list.rsid,
                aid: leiku.GetUrlParam('aid'),
                idea: this.message,
                auditstatus: this.radio,// 0不通过
                ybmid: this.list.ybmid,
                xbmid: this.list.xbmid,
            }
            leiku.post(this.baseUrl() + '/api/2020122290541319', params, res => {
                this.$notify({ type: 'success', message: '保存成功！' });
                this.msgClose();
                this.showMsg = false;
                window.location.reload()
            })
        }
    }
})